package com.woniu.service.impl;

import com.woniu.entity.User;
import com.woniu.mapper.UserMapper;
import com.woniu.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public User findById(Integer id) {
        return userMapper.findById(id);
    }

    @Override
    public List<User> findByCondition(User user) {
        return userMapper.findByCondition(user);
    }

    @Override
    public User findByName(String name) {
        return userMapper.findByName(name);
    }

    @Override
    public Integer add(User user) {
        return userMapper.add(user);
    }

    @Override
    public Integer update(User user) {
        return userMapper.update(user);
    }

    @Override
    public Integer delete(Integer id) {
        return userMapper.delete(id);
    }

    @Override
    public Map<String, Object> login(User user) {
        User name = userMapper.findByName(user.getName());
        HashMap<String, Object> map = new HashMap<>();
        if (name == null) {
            map.put("code",500);
            map.put("msg","用户名错误");
        }else if(!name.getPassword().equals(user.getPassword())){
            map.put("code",500);
            map.put("msg","用户名或密码错误");
        }else {
            map.put("code",200);
            map.put("msg","恭喜你，登录成功");
            
        }
        return map;
    }
}
